package ControlLayer;

import DBLayer.*;
import ModelLayer.Clothing;
import ModelLayer.Equipment;
import ModelLayer.GunReplicas;
import ModelLayer.Product;

public class ProductControl {
	DBEquipment equip = new DBEquipment();
	DBClothing cloth = new DBClothing();
	DBGunReplicas gunrep = new DBGunReplicas();

	//Denne metode opretter et gunReplicas produkt med de parametre som bliver sendt med
public void createGunReplicas(int pid, String name, int purchacePrice, int salesPrice, int rentPrice, String countryOfOrigen, int minStock, String descriptionType, String fabric, String calibre) throws Exception
{
	try
	{
		Product g = findProductByPid(pid);
		if(g == null)
		{
			throw new Exception("Vare findes allerede");
		}
		else
		{
			g = new GunReplicas();
			g.setpId(pid);
			g.setName(name);
			g.setPurchasePrice(purchacePrice);
			g.setSalesPrice(salesPrice);
			g.setRentPrice(rentPrice);
			g.setCountryOfOrigen(countryOfOrigen);
			g.setMinStock(minStock);
			g.setDescriptionType(descriptionType);
			g.setFabric(fabric);
			g.setCalibre(calibre);
			gunrep.addGunReplicas(g);
		}
	}
	catch(IndexOutOfBoundsException i)
	{
	}	
}
//Denne metode opretter et clothing produkt med de parametre som bliver sendt med
public void createClothing(int pid, String name, int purchacePrice, int salesPrice, int rentPrice, String countryOfOrigen, int minStock, String descriptionType, String size, String color) throws Exception
{
	try
	{
		Product p = findProductByPid(pid);
		if(p == null)
		{
			throw new Exception("Vare findes allerede");
		}
		else
		{
			Clothing c = new Clothing();
			c.setpId(pid);
			c.setName(name);
			c.setPurchasePrice(purchacePrice);
			c.setSalesPrice(salesPrice);
			c.setRentPrice(rentPrice);
			c.setCountryOfOrigen(countryOfOrigen);
			c.setMinStock(minStock);
			c.setDescriptionType(descriptionType);
			c.setSize(size);
			c.setColour(color);
			cloth.addClothing(c);
		}
	}
	catch(IndexOutOfBoundsException i)
	{
	}
}
//Denne metode opretter et equipment produkt med de parametre som bliver sendt med
public void createEquipment(int pid, String name, int purchacePrice, int salesPrice, int rentPrice, String countryOfOrigen, int minStock, String descriptionType, String description) throws Exception
{

	try
	{
		Product e = new Equipment();
		e = findProductByPid(pid);
		if(e == null)
		{
			throw new Exception("Vare findes allerede");
		}
		else
		{
			e.setpId(pid);
			e.setName(name);
			e.setPurchasePrice(purchacePrice);
			e.setSalesPrice(salesPrice);
			e.setRentPrice(rentPrice);
			e.setCountryOfOrigen(countryOfOrigen);
			e.setMinStock(minStock);
			e.setDescriptionType(descriptionType);
			e.setDescription(description);
			equip.addEquipment(e);
		}
	}
	catch(IndexOutOfBoundsException i)
	{
	}
	
}
	//Denne metode finder et produkt ud fra medsendt pid og retunerer dette.
public Product findProductByPid(int pid)
{
	Product p = null;
	
	try
	{
		Product e = new Equipment();
		e = equip.findEquipment(pid);
		if(e != null)
		{
			p = e;
		}
		Product c = new Clothing();
		c = cloth.findClothing(pid);
		if(c != null)
		{
			p = c;
		}
		Product g = new GunReplicas();
		g = gunrep.findGunReplicas(pid);
		if(g != null);
		{
			p = g;
		}
	}
	catch(Exception e)
	{
		
	}
	return p;
}
//endnu ikke implementeret
public void updateGunReplicasByPid(int pid, String name, int purchacePrice, int salesPrice, int rentPrice, String countryOfOrigen, int minStock, String descriptionType, String fabric, String calibre)
{
	
}
//endnu ikke implementeret
public void updateClothingByPid(int pid, String name, int purchacePrice, int salesPrice, int rentPrice, String countryOfOrigen, int minStock, String descriptionType, String size, String color)
{
	
}
//endnu ikke implementeret
public void updateEquipmentByPid(int pid, String name, int purchacePrice, int salesPrice, int rentPrice, String countryOfOrigen, int minStock, String descriptionType, String description)
{
	
}
}
